#! /usr/bin/env python
import waflib.Options
from waf_dynamo import dmsdk_add_files

def configure(conf):
    pass

def build(bld):
    resource = bld.stlib(features = 'cxx ddf',
                         includes = '. ../proto',
                         source = bld.path.ant_glob('*.cpp') + bld.path.ant_glob('providers/*.cpp'),
                         protoc_includes = '../proto',
                         proto_gen_py = True,
                         target = 'resource')

    resource.source.append('async/load_queue.cpp');
    if 'web' in bld.env.PLATFORM:
         resource.source.append('async/load_queue_sync.cpp');
    else:
         resource.source.append('async/load_queue_threaded.cpp');

    if bld.env.PLATFORM in ('armv7-android','arm64-android'):
        resource.source.append('mount/mount_android.cpp');
    elif bld.env.PLATFORM in ('x86_64-linux','x86_64-macos','arm64-macos','arm64-ios','x86_64-ios'):
        resource.source.append('mount/mount_mmap.cpp');
    else:
        resource.source.append('mount/mount_generic.cpp');

    resource.source += bld.path.parent.ant_glob('proto/resource/*')

    if not waflib.Options.options.skip_build_tests:
        bld.recurse('test')

    # the dmsdk_add_files needs to be after a build group for some reason
    dmsdk_add_files(bld, '${PREFIX}/sdk/include/dmsdk', 'dmsdk')

    bld.install_files('${PREFIX}/share/proto/resource', '../proto/resource/resource_ddf.proto')
    bld.install_files('${PREFIX}/share/proto/resource', '../proto/resource/liveupdate_ddf.proto')

    bld.install_files('${PREFIX}/include/resource', 'resource.h')
    bld.install_files('${PREFIX}/include/resource', 'resource_archive.h')
    bld.install_files('${PREFIX}/include/resource', 'resource_chunk_cache.h')
    bld.install_files('${PREFIX}/include/resource', 'resource_manifest.h')
    bld.install_files('${PREFIX}/include/resource', 'resource_mounts.h')
    bld.install_files('${PREFIX}/include/resource', 'resource_util.h')
    bld.install_files('${PREFIX}/include/resource', 'resource_verify.h')
    bld.install_files('${PREFIX}/include/resource/providers', 'providers/provider.h')
    bld.install_files('${PREFIX}/lib/python', 'waf_resource.py')
    bld.install_files('${PREFIX}/bin', 'arcc.py')

